import os

WORK_DIR = '\\\\lcnas\\xishu16t2020_1\choosefc2\\'


def rename_info(path):
    with open(path, 'r', encoding='cp437') as f1:
        a = f1.readlines()
        f1.close()
    with open(path + '.txt', 'w', encoding='cp437') as f2:
        for i in a:
            f2.write(i.replace('fc2-ppv ', 'FC2-'))
    f2.close()
    os.remove(path)
    os.rename(path + '.txt', path)


if __name__ == '__main__':
    dirs = os.listdir(WORK_DIR)
    for d in dirs:
        do_dir = WORK_DIR + d + '\\'
        do_dirs = os.listdir(do_dir)
        print(d)
        for i in do_dirs:
            new_name = i.replace('fc2-ppv ', 'FC2-')
            if i[-4:] == '.nfo':
                rename_info(do_dir + i)
                os.rename(do_dir + i, do_dir + new_name)
            else:
                os.rename(do_dir + i, do_dir + new_name)
        new_name_d = d.replace('fc2-ppv ', 'FC2-')
        os.rename(WORK_DIR + d, WORK_DIR + new_name_d)